package com.kpmg.datalake.common.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.kpmg.datalake.common.service.RbacFunctionService;
import com.kpmg.datalake.common.vo.RbacFunctionVo;
import com.kpmg.datalake.common.vo.RbacRoleVo;
import com.kpmg.datalake.common.vo.RbacVo;
import com.kpmg.datalake.common.vo.ServerResponse;
import com.kpmg.datalake.operatelog.annotation.OptLog;
import com.kpmg.datalake.operatelog.enums.LogTypeEnum;

@RestController
@RequestMapping(value = "/rbac")
public class RbacFunctionController {

  @Autowired
  private RbacFunctionService rbacFunctionService;

  /**
   * 获取功能权限树
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getADSystemInfo")
  public ServerResponse<JSONObject> getADSystemInfo(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.getADSystemInfo(rbacVo);
  }

  /**
   * 获取功能权限树
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getRbacFunctionTree")
  public ServerResponse rbacFunctionTreeJsonObject(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.rbacFunctionTreeJsonObject(rbacVo);
  }

  /**
   * 获取功能权限树
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getVbaFunctionTree")
  public ServerResponse vbaFunctionTreeJsonObject() {
    return rbacFunctionService.vbaTreeJsonObject();
  }

  /**
   * 获取用户所有功能权限列表
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getRbacFunctionList")
  public ServerResponse getRbacFunctionList(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.getRbacFunctions(rbacVo);
  }

  /**
   * 获取DATA用户列表
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getUserBusiness")
  public ServerResponse getUserBusiness(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.getUserBusiness(rbacVo);
  }

  /**
   * 获取数据权限列表
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getProjectList")
  public ServerResponse getProjectList(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.getProjectList(rbacVo);
  }

  /**
   * 获取DATA角色列表
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getRbacRoleList")
  public ServerResponse getRbacRoleList() {
    return rbacFunctionService.getRbacRoleList();
  }

  /**
   * 添加用户角色关联
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/addUserRole")
  public ServerResponse addUserRole(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.addUserRole(rbacVo);
  }

  /**
   * 新建DATA用户
   * 
   * @param rbacUserVo
   * @return
   */
  @PostMapping(value = "/addUserForDATA")
  @OptLog(logType = LogTypeEnum.SECURITY, module = "system", description = "用户新增")
  public ServerResponse addUserForDATA(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.addUserForDATA(rbacVo);
  }

  /**
   * 删除DATA用户
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/deleteUserForDATA")
  @OptLog(logType = LogTypeEnum.SECURITY, module = "system", description = "用户删除")
  public ServerResponse deleteUserForDATA(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.deleteUserForDATA(rbacVo);
  }


  /**
   * 获取BA用户列表
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getUserBA")
  public ServerResponse getUserBA(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.getUserForBA(rbacVo);
  }

  /**
   * 新建BA用户
   * 
   * @param rbacUserVo
   * @return
   */
  @PostMapping(value = "/addUserForBA")
  @OptLog(logType = LogTypeEnum.SECURITY, module = "system", description = "增加BA用户")
  public ServerResponse addUserForBA(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.addUserForBA(rbacVo);
  }

  /**
   * 删除BA用户
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/deleteUserBA")
  @OptLog(logType = LogTypeEnum.SECURITY, module = "system", description = "删除BA用户")
  public ServerResponse deleteUserForBA(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.deleteUserForBA(rbacVo);
  }

  /**
   * 获取所有project
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/getAllProject")
  public ServerResponse getAllProject() {
    return rbacFunctionService.getAllProject();
  }

  /**
   * 新建角色
   * 
   * @param rbacRoleVo
   * @return
   */
  @PostMapping(value = "/addRole")
  public ServerResponse addRole(@RequestBody RbacRoleVo rbacRoleVo) {
    return rbacFunctionService.addRole(rbacRoleVo);
  }

  /**
   * 新建功能
   * 
   * @param rbacFunctionVo
   * @return
   */
  @PostMapping(value = "/addFunction")
  public ServerResponse addFunction(@RequestBody RbacFunctionVo rbacFunctionVo) {
    return rbacFunctionService.addFunction(rbacFunctionVo);
  }

  /**
   * 用户状态更新(1:启用;0:禁用)
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/updateUserStatus")
  public ServerResponse updateUserStatus(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.updateUserStatus(rbacVo);
  }


  /**
   * 角色状态更新(1:启用;0:禁用)
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/updateRoleStatus")
  public ServerResponse updateRoleStatus(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.updateRoleStatus(rbacVo);
  }

  /**
   * 删除角色
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/deleteRoleStatus")
  public ServerResponse deleteRoleStatus(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.deleteRoleStatus(rbacVo);
  }

  /**
   * 用户角色权限修改
   * 
   * @param rbacVo
   * @return
   */
  @PostMapping(value = "/userAddRole")
  public ServerResponse userAddRole(@RequestBody RbacVo rbacVo) {
    return rbacFunctionService.userAddRole(rbacVo);
  }

}
